package dp.mobile.entity;

import java.io.Serializable;
import java.util.Random;

import org.w3c.dom.Node;

import dp.mobile.entity.tower.TowerFactory;
import dp.mobile.glwrapper.GLTexture;
import dp.mobile.glwrapper.GameRenderer;
import dp.mobile.system.Utilities;

public class BulletData implements Serializable {
	private static final long serialVersionUID = 3679654015549046041L;

	protected BulletData() {
		//Initialize
		m_Buff		= 0;
		m_Area		= -1;
		m_Damage	= 0;
		m_Duration	= 200;
		m_Image		= null;

		rand = new Random();
	}

	public BulletData(Node root) {
		//Default
		this();

		//For each child
		int childCount = root.getChildNodes().getLength();
		for (int i = 0; i < childCount; i++) {
			//Get variable
			Node child = root.getChildNodes().item(i);
			if (child.getNodeType() == Node.TEXT_NODE) continue;
			String tag		= child.getNodeName();
			String value	= child.getFirstChild().getNodeValue();

			//Check based on tag name
			if (tag.equals("area"))				m_Area = Integer.parseInt(value);
			else if (tag.equals("buff"))		m_Buff = Integer.parseInt(value);
			else if (tag.equals("damage"))		m_Damage = Integer.parseInt(value);
			else if (tag.equals("duration"))	m_Duration = Integer.parseInt(value);
			else if (tag.equals("image"))		m_Image	= GameRenderer.instance().allocateTexture(Utilities.BULLET_FOLDER + "/" + value + ".png");
		}
	}

	public int getArea()		{	return m_Area;		}
	public int getDamage()		{	return m_Damage;	}
	public GLTexture getImage()	{	return m_Image;		}
	public long getDuration()	{	return m_Duration;	}
	public Node getBuffData() 	{
		return TowerFactory.instance().getBuffData(m_Buff);
	}

	//Data
	protected int	m_Buff;
	protected int	m_Area;
	protected int	m_Damage;
	protected long	m_Duration;
	protected GLTexture m_Image;
	
	protected Random rand;
}
